package com.thxy.jxgl.mubiaoka.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.thxy.jxgl.filter.ToCh;
import com.thxy.jxgl.javaBean.khxm;
import com.thxy.jxgl.mubiaoka.manager.MubiaokaManager;
import com.thxy.jxgl.mubiaoka.manager.XiangmuManager;

/**
 * Servlet implementation class XiangmuServlet
 */
public class XiangmuServlet extends HttpServlet {
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String method = request.getParameter("method") == null?"":request.getParameter("method");
		request.setCharacterEncoding("gbk");
        if("addxiangmu".equals(method))
        {
            khxm xm=(khxm)request.getSession().getAttribute("xiangmu");
            request.getSession().removeAttribute("xiangmu");
            String xmname=ToCh.toChinese(xm.getXm_name());
            String xmno=xm.getXm_id();
        	boolean ins=XiangmuManager.getInstance().addXm(xmno, xmname);
        }else if ("delexiangmu".equals(method)) {
			String xmno=request.getParameter("xmno");
			XiangmuManager.getInstance().deleXm(xmno);
		}else if ("editxiangmu".equals(method)) {
			String xmno=request.getParameter("xmno");
			String xmname=request.getParameter("xm_name").toString();
			boolean upd=XiangmuManager.getInstance().updateXm(xmname, xmno);
		}
        
		List xmList=new ArrayList();
		xmList=XiangmuManager.getInstance().getXiangmu();
		request.getSession().setAttribute("xmList",xmList );
		request.getRequestDispatcher("/mbkgl/xiangmu.jsp").forward(request, response);

		}
	
}
